<!DOCTYPE html>
<title>This tests that events don't continue to target a slider thumb if the media element is deleted while scrubbing.</title>
<script src="media-controls.js"></script>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<input type="button" value="Click Me!">
<audio autoplay controls></audio>
<script>
async_test(function(t) {
    var audio = document.querySelector("audio");
    audio.src = "content/test.oga";
    audio.onplaying = t.step_func(function() {
        var seekCoords = mediaControlsButtonCoordinates(audio, "timeline");
        var x = seekCoords[0];
        var y = seekCoords[1];

        // Click in the slider to get the thumb under the mouse.
        // clicking in controller.
        eventSender.mouseMoveTo(x, y);
        eventSender.mouseDown();
        eventSender.mouseUp();

        // Click slider to scrub, leave the mouse down.
        // clicking on thumb.
        eventSender.mouseDown();
        eventSender.mouseMoveTo(x, y + 20);

        // Remove the element after seeking started
        audio.onseeking = t.step_func(deleteAudio);
    });

    function deleteAudio() {
        // deleting audio element.
        audio.parentNode.removeChild(audio);

        setTimeout(t.step_func(buttonClick), 10);
    }

    function buttonClick() {
        gc();

        assert_equals(document.querySelector("audio"), null);

        // click the button
        var button = document.querySelector("input");
        button.onmouseup = t.step_func_done();
        eventSender.mouseMoveTo(button.offsetLeft + 20, button.offsetTop + 7);
        eventSender.mouseDown();
        eventSender.mouseUp();
    }
});
</script>